package lesson;

/**
 * Function: BinarySearch
 * Editor: HexWarrior6
 * Date: 2023/11/9 10:12
 */
public class BSearch {
    int []list = {1,2,3,4};
    int left = 0, right = list.length - 1;
    static int BSearch(int[] list, int val, int left, int right) {
        int middle = (left + right) / 2;
        if (val < list[middle]) {
            return BSearch(list, val, left, middle - 1);
        } else if (val > list[middle]) {
            return BSearch(list, val, middle + 1, right);
        } else {
            return middle;
        }
    }

    public static void main(String[] args) {
        int []list = {1,2,3,4};
        System.out.println(BSearch(list, 1, 1, 4));
    }
}